<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>贷款申请</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            margin: 0;
            padding: 20px;
            min-height: 100vh;
        }

        .container {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            border-radius: 15px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }

        .header {
            background: linear-gradient(135deg, #4CAF50, #45a049);
            color: white;
            padding: 30px;
            text-align: center;
        }

        .header h1 {
            margin: 0;
            font-size: 28px;
            font-weight: 300;
        }

        .header p {
            margin: 10px 0 0;
            opacity: 0.9;
            font-size: 16px;
        }

        .form-container {
            padding: 40px;
        }

        .form-group {
            margin-bottom: 25px;
        }

        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: 500;
            font-size: 16px;
        }

        .form-control {
            width: 100%;
            padding: 15px;
            border: 2px solid #e1e8ed;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s ease;
            box-sizing: border-box;
        }

        .form-control:focus {
            outline: none;
            border-color: #4CAF50;
            box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
        }

        .form-control::placeholder {
            color: #999;
        }

        .file-input-wrapper {
            position: relative;
            overflow: hidden;
            display: inline-block;
            width: 100%;
        }

        .file-input-wrapper input[type=file] {
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0;
            width: 100%;
            height: 100%;
            cursor: pointer;
        }

        .file-input-button {
            display: block;
            width: 100%;
            padding: 15px;
            background: #f8f9fa;
            border: 2px dashed #ccc;
            border-radius: 8px;
            text-align: center;
            color: #666;
            font-size: 16px;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .file-input-button:hover {
            border-color: #4CAF50;
            background: #e8f5e9;
            color: #2e7d32;
        }

        .file-name {
            margin-top: 10px;
            font-size: 14px;
            color: #666;
            font-style: italic;
        }

        .submit-btn {
            width: 100%;
            padding: 16px;
            background: linear-gradient(135deg, #4CAF50, #45a049);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 18px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .submit-btn:hover {
            background: linear-gradient(135deg, #45a049, #3d8b40);
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(76, 175, 80, 0.3);
        }

        .submit-btn:active {
            transform: translateY(0);
        }

        .navigation {
            text-align: center;
            margin-top: 20px;
        }

        .nav-link {
            color: #4CAF50;
            text-decoration: none;
            font-weight: 500;
            padding: 10px 20px;
            border: 2px solid #4CAF50;
            border-radius: 25px;
            transition: all 0.3s ease;
        }

        .nav-link:hover {
            background: #4CAF50;
            color: white;
        }

        @media (max-width: 768px) {
            .container {
                margin: 10px;
                border-radius: 10px;
            }

            .form-container {
                padding: 20px;
            }

            .header {
                padding: 20px;
            }

            .header h1 {
                font-size: 24px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>贷款申请</h1>
            <p>请填写以下信息完成贷款申请</p>
        </div>

        <div class="form-container">
            <form action="/loan/addLoan" method="post" enctype="multipart/form-data">
               <h2 style="color: red" th:text="${msg}"></h2>
                <div class="form-group">
                    <label for="userName">姓名</label>
                    <input type="text" id="userName" name="userName" class="form-control" placeholder="请输入您的姓名" required>
                </div>

                <div class="form-group">
                    <label for="price">贷款金额</label>
                    <input type="number" id="price" name="price" class="form-control" placeholder="请输入贷款金额" min="1" required>
                </div>

                <div class="form-group">
                    <label for="term">贷款期限</label>
                    <input type="text" id="term" name="term" class="form-control" placeholder="请输入贷款期限（如：12个月）" required>
                </div>

                <input th:if="${session.user != null}" type="hidden" name="userId" th:value="${session.user.userId}">

                <div class="form-group">
                    <label>上传相关图片</label>
                    <div class="file-input-wrapper">
                        <div class="file-input-button">
                            📎 选择文件
                        </div>
                        <input type="file" name="image" accept="image/*" id="imageInput">
                    </div>
                    <div class="file-name" id="fileName">未选择文件</div>
                </div>

                <button type="submit" class="submit-btn">提交申请</button>
            </form>

            <div class="navigation">
                <a th:href="@{/loan/selectById(userId=${session.user.userId})}" class="nav-link">查看申请记录</a>
            </div>
        </div>
    </div>

    <script>
        // 文件选择后显示文件名
        document.getElementById('imageInput').addEventListener('change', function(e) {
            const fileName = e.target.files[0] ? e.target.files[0].name : '未选择文件';
            document.getElementById('fileName').textContent = fileName;
        });

        // 表单提交前验证
        document.querySelector('form').addEventListener('submit', function(e) {
            const userName = document.getElementById('userName').value.trim();
            const price = document.getElementById('price').value.trim();
            const term = document.getElementById('term').value.trim();

            if (!userName || !price || !term) {
                e.preventDefault();
                alert('请填写所有必填字段');
                return;
            }

            if (isNaN(price) || Number(price) <= 0) {
                e.preventDefault();
                alert('请输入有效的贷款金额');
                return;
            }
        });
    </script>
</body>
</html>
